package com.molyfun.parents.activity.store.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.molyfun.parents.R;
import com.molyfun.parents.activity.coursecenter.model.SubjectListResponse;
import com.molyfun.parents.activity.store.view.ProductView;
import com.molyfun.parents.impl.IHorizontalTag;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 *
 */
public class ProductAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    Context mContext;
    private List<SubjectListResponse.SubjectBrief> mList;
//    private static final int TYPE_HEADER = 1001;
//    private static final int TYPE_CONTENT = 1002;

    private List<IHorizontalTag> mHeaderList;

    public ProductAdapter(Context context) {
        this.mContext = context;
    }

    public void refreshData(List<SubjectListResponse.SubjectBrief> list) {
        this.mList = list;
        notifyDataSetChanged();
    }

    public void clearAll() {
        if (mList != null) {
            mList.clear();
            notifyDataSetChanged();
        }
    }

    public void setHeaderList(List<IHorizontalTag> headerList){
        this.mHeaderList = headerList;
        notifyDataSetChanged();
    }

    public void addAll(List<SubjectListResponse.SubjectBrief> list) {
        if (mList != null) {
            this.mList.addAll(list);
            notifyDataSetChanged();
        }
    }
//
//    @Override
//    public int getItemViewType(int position) {
//        if (position == 0) {
//            return TYPE_HEADER;
//        } else {
//            return TYPE_CONTENT;
//        }
//    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//        switch (viewType) {
//            case TYPE_HEADER:
//                return new ProductHeaderViewHolder(LayoutInflater.from(parent.getContext())
//                        .inflate(R.layout.layout_class_center_title, parent, false));
//            case TYPE_CONTENT:
//            default:
                return new ProductBriefViewHolder(LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.layout_product_cell, parent, false));
//        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
//        switch (getItemViewType(position)){
//            case TYPE_HEADER:
//                ProductHeaderViewHolder productHeaderViewHolder = (ProductHeaderViewHolder) holder;
//                if(mHeaderList != null && mHeaderList.size() > 0){
//                    productHeaderViewHolder.mHorizontalTagBar.initDataList(mHeaderList);
//                }
//
//                break;
//            case TYPE_CONTENT:
                final SubjectListResponse.SubjectBrief productBean = mList.get(position);
                ProductBriefViewHolder productBriefViewHolder = (ProductBriefViewHolder) holder;
                productBriefViewHolder.mProductView.initData(productBean);
//                break;
//        }
    }

    public class ProductBriefViewHolder extends RecyclerView.ViewHolder {

        @InjectView(R.id.product_layout)
        ProductView mProductView;

        public ProductBriefViewHolder(View view) {
            super(view);
            ButterKnife.inject(this, view);
        }
    }

//    public class ProductHeaderViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
//
//        @InjectView(R.id.pick_btn)
//        TextView mPickBtn;
//        @InjectView(R.id.horizontal_tag_bar)
//        HorizontalPickBar mHorizontalTagBar;
//        @InjectView(R.id.msg_icon)
//        ImageView mMsgIcon;
//        @InjectView(R.id.search_icon)
//        ImageView mSearch;
//
//        public ProductHeaderViewHolder(View view) {
//            super(view);
//            ButterKnife.inject(this, view);
//
//            mMsgIcon.setOnClickListener(this);
//            mSearch.setOnClickListener(this);
//            mPickBtn.setOnClickListener(this);
//            if (PushMsgCacheCenter.getInstance().getmCurrentUnreadCount() > 0) {
//                mMsgIcon.setImageResource(R.mipmap.ic_nav_msg_unread);
//            } else {
//                mMsgIcon.setImageResource(R.mipmap.ic_nav_msg);
//            }
//        }
//
//        @Override
//        public void onClick(View v) {
//            switch (v.getId()){
//                case R.id.msg_icon:
//                    MineMsgActivity.startActivity(mContext);
//                    break;
//                case R.id.search_icon:
//                    CourseSearchActivity.startActivity(mContext);
//                    break;
//                case R.id.pick_btn:
//                    CoursePickActivity.startActivity(mContext);
//                    break;
//            }
//        }
//    }


    @Override
    public int getItemCount() {
        if (mList == null || mList.size() == 0) {
            return 0;
        }
        return mList.size();
    }

}
